<template>
	<view class="login">
		<image src="../../static/image/fanhui.png" class="fanhui" @click="back"></image>
		<view class="head_img">
			<image src="../../static/image/toxiang.png" class="img"></image>
		</view>
		<view class="content">
			<view class="ipts">
				<input type="number" v-model='phone' placeholder="手机号" />
			</view>
			<view class="ipts">
				<view><input type="number" placeholder="验证码" v-model='captcha'/></view>
				<view class='blue' v-show='stus == true' @click='code'>{{text}}</view>
				<view class='grays' v-show='stus == false'>{{text}}S重新获取</view>
			</view>
			<view class="ipts">
				<input type="text" password v-model='pwd' placeholder="设置初始密码" />
			</view>
			<img src="../../static/image/zhuce.png" class="denglu" @click='goRegister()'/>
			<checkbox-group class="block" @change="CheckboxChange">
				<view class="cu-form-group">
					<checkbox class='round blue' :class="checked==true?'checked':''" :checked="checked"></checkbox>
					<view class="title">我已阅读并同意《用户服务协议》</view>
				</view>
			</checkbox-group>
		</view>
	</view>
</template>

<script>
	// import uniIcons from "@/components/uni-ui/uni-icons/uni-icons.vue"
	export default {
		data() {
			return {
				sunmax: 60,
				stus: true, //倒计时标识
				phone: '',
				text: '获取验证码',
				codes: '',
				pwd: '',
				captcha: '',
				img: '../../static/image/beijing.png',
				checked:false
			}
		},
		onLoad() {},
		// components: {uniIcons},
		methods: {
			//获取验证码
			code() {
				if ((/^1[345789]\d{9}$/.test(this.phone))) {
					this.stus = false;
					this.text = this.sunmax;
					let timeInt = setInterval(() => {
						this.text--
						if (this.text <= 0) {
							this.stus = true;
							this.text = '获取验证码';
							clearInterval(timeInt)
						}
					}, 1000)
					var obj = {
						mobile: this.phone
					}
					this.$common.requests('/api/user/sendSMS', obj).then(res => {
						this.$api.msg(res.data.msg);
						if (res.data.code == 1) {
							
						}
					})
				} else {
					this.$api.msg('请输入正确的手机号');
				}
			},
			//协议同意
			CheckboxChange() {
				if(this.checked == true){
					this.checked = false
				}else{
					this.checked = true
				}
			},
			back(){
				uni.navigateBack()
			},
			goRegister() {
				if (!this.checked) {
					this.$api.msg('请勾选用户服务协议');
					return;
				}
				if (!this.phone) {
					this.$api.msg('请输入账号');
					return;
				}
				if (!this.captcha) {
					this.$api.msg('请输入验证码');
					return;
				}
				if (!this.pwd) {
					this.$api.msg('请输入密码');
					return;
				}
				var obj = {
					mobile: this.phone,
					password: this.pwd,
					captcha: this.captcha,
				}
				this.$common.requests('/api/user/register', obj).then(res => {
					this.$api.msg(res.data.msg);
					if (res.data.code == 1) {
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 800)
					}
			
				})
			}
		}
	}
</script>

<style scoped>
	.login {
		height: 100vh;
	}

	.all {
		padding: 0;
		margin: 0;
		font-size: 32upx;
		color: #333333;
	}

	.head_img {
		padding: 160upx 0 10upx 0;
		text-align: center;
	}

	.img {
		width: 110px;
		height: 110px;
	}

	.content {
		padding: 30upx 40upx;
		text-align: center;
	}

	.ipts {
		margin: 20upx 0;
		border-bottom: 1px solid #EAEAEA !important;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.ipts input {
		height: 100upx !important;
		text-align: left;
	}

	.denglu {
		width: 100%;
		height: 80upx;
		margin: 30upx 0 20upx 0;
	}

	.blue {
		font-size: 14px;
		color: #4C68FF;
		letter-spacing: 1px;
	}

	.grays {
		color: gray;
		font-size: 14px;
		letter-spacing: 1px;
	}

	.register {
		width: 100%;
		position: absolute;
		bottom: 20px;
		left: 0;
	}

	.fanhui {
		position: absolute;
		top: 35px;
		left: 1rem;
		width: 7px;
		height: 15px;
	}

	.block {
		width: 100%;
		position: absolute;
		bottom: 20px;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.title{
		margin-left: 10upx;
	}
</style>
